package com.blogsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blogsystem.entity.Article;
import com.blogsystem.entity.Comment;
import com.blogsystem.mapper.CommentMapper;
import com.blogsystem.service.CommentService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    private final CommentMapper commentMapper;

    public CommentServiceImpl(CommentMapper commentMapper) {
        this.commentMapper = commentMapper;
    }

    public List<Comment> getAllCommentsByUserId(Integer userId) {
        // 这里可以实现获取用户所有评论的逻辑
        // 返回一个包含所有评论的列表
        if (userId != null) {
            return commentMapper.selectList(new QueryWrapper<Comment>()
                    .eq("user_id", userId)
                    .orderByDesc("create_time"));
        }
        return null;

    }
    public List<Comment> getCommentsByArticleId(Integer articleId) {
        // 这里可以实现获取文章所有评论的逻辑
        // 返回一个包含所有评论的列表
        if (articleId != null) {
            return commentMapper.selectList(new QueryWrapper<Comment>()
                    .eq("article_id", articleId)
                    .orderByDesc("create_time"));
        }
        return null;
    }


}